﻿using System;
using System.Configuration;

namespace openSourceC.Daylife
{
	/// <summary>
	///		Summary description for DaylifeSection.
	/// </summary>
	public class DaylifeSection : ConfigurationSection
	{
		/// <summary>Gets the configuration file section name.</summary>
		public const string SectionName = "openSourceC/daylife";

		private static DaylifeSection _configSection = null;
		private static object _configSectionLock = new object();


		#region Instance

		/// <summary>
		///		Gets the singleton instance of <see cref="DaylifeSection"/>.
		/// </summary>
		public static DaylifeSection Instance
		{
			get
			{
				if (_configSection == null)
				{
					lock (_configSectionLock)
					{
						if (_configSection == null)
						{
							_configSection = (DaylifeSection)ConfigurationManager.GetSection(SectionName);

							if (_configSection == null)
							{
								throw new ConfigurationErrorsException(string.Format("Section {0} does not exist in the configuration file.", SectionName));
							}
						}
					}
				}

				return _configSection;
			}
		}

		#endregion

		#region Public Properties

		/// <summary></summary>
		[ConfigurationProperty("accessKey", IsRequired = true)]
		public string AccessKey
		{
			get { return (string)base["accessKey"]; }
			set { base["accessKey"] = value; }
		}

		/// <summary></summary>
		[ConfigurationProperty("baseApiAddress", IsRequired = true)]
		public string BaseApiAddress
		{
			get { return (string)base["baseApiAddress"]; }
			set { base["baseApiAddress"] = value; }
		}

		/// <summary></summary>
		[ConfigurationProperty("batchApiPath", IsRequired = true)]
		public string BatchApiPath
		{
			get { return (string)base["batchApiPath"]; }
			set { base["batchApiPath"] = value; }
		}

		/// <summary></summary>
		[ConfigurationProperty("publicApiPath", IsRequired = true)]
		public string PublicApiPath
		{
			get { return (string)base["publicApiPath"]; }
			set { base["publicApiPath"] = value; }
		}

		/// <summary></summary>
		[ConfigurationProperty("sharedSecret", IsRequired = true)]
		public string SharedSecret
		{
			get { return (string)base["sharedSecret"]; }
			set { base["sharedSecret"] = value; }
		}

		/// <summary></summary>
		[ConfigurationProperty("sourceFilterId", IsRequired = false)]
		public string SourceFilterId
		{
			get { return (string)base["sourceFilterId"]; }
			set { base["sourceFilterId"] = value; }
		}

		#endregion
	}
}
